﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace BuildPlanner.Classes
{
    public class TimeValidationRule : ValidationRule
    {

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            TimeSpan time = TimeSpan.Zero;

            try
            {
                if (((string)value).Length > 0)
                    time = TimeSpan.ParseExact((String)value, @"h\:mm\:ss\.ff", CultureInfo.InvariantCulture);
                else
                    return new ValidationResult(false, "Please enter a positive time value.");
            }
            catch (Exception e)
            {
                return new ValidationResult(false, "Illegal characters or " + e.Message);
            }

            if (time < TimeSpan.Zero)
            {
                return new ValidationResult(false, "Please enter a positive time value.");
            }
            else
            {
                return new ValidationResult(true, null);
            }
        }
    }
}
